package com.bookstore.dao.impl;

import com.bookstore.dao.BaseDao;
import com.bookstore.dao.ProductDao;
import com.bookstore.entity.Product;
import com.bookstore.entity.User;

import java.util.List;

public class ProductDaoImpl extends BaseDao implements ProductDao {
    @Override
    public int insertProduct(Product product) {
        String sql = "insert into t_product values(?,?,?,?,?,?,?)";
        return super.update(sql,product.getId(), product.getName(), product.getPrice(), product.getCategory(), product.getPnum(), product.getImgurl(), product.getDescription());
    }

    @Override
    public int updateProduct(Product product) {
        String sql = "update t_product set name=?,price=?,category=?,pnum=?,imgurl=?,description=? where id=?";
        return super.update(sql, product.getName(), product.getPrice(), product.getCategory(), product.getPnum(), product.getImgurl(), product.getDescription(), product.getId());
    }

    @Override
    public int deleteProduct(int productId) {
        String sql = "delete from t_product where id=?";
        return super.update(sql, productId);
    }

    @Override
    public List<Product> queryAllProduct() {
        String sql = "select * from t_product";
        return super.queryMore(Product.class, sql);
    }

    @Override
    public Product queryProductId(int productId) {
        String sql = "select * from t_product where id=?";
        return super.queryOne(Product.class, sql, productId);
    }

    @Override
    public List<Product> queryLimiteProduct(Integer start,Integer maxNum) {
        String sql = "select * from t_product LIMIT ?,?";
        return super.queryMore(Product.class, sql,start,maxNum);
    }

    @Override
    public int queryProductCount() {
        String sql = "select COUNT(*) from t_product ";
        return Integer.valueOf(super.queryItem(sql).toString());
    }
}
